

var QrH5MubanModel = $.extend(TradeModel, {
    selRow: null,
    editor:{
        title: "属性",
        winid:'QrH5Muban_EditForm',
        formid:'QrH5Muban_EditForm_fm',
        width:720,
        height:300
    },
    postAction: 'add',
    url: '/qrmgr/qrh5muban',
    title: "标题",
    idField: "mubanId",
    titleField: "mubanName",
    toolbar: 'QrH5Muban_Toolbar',
    datagrid: 'QrH5Muban_Grid'
});

QrH5MubanModel.reload =function() {
    ReloadQrH5MubanList();
    $('#QrH5Muban_EditForm').dialog('close');
}


function fun_FindRowById(id) {
    var cRows = $('#QrH5Muban_Grid').datagrid('getRows');
    if (id == undefined || id == '' || id == null) return null;
    for (i = 0; i < cRows.length; i++) {
        if (cRows[i][QrH5MubanModel.idField] == id) {
            return cRows[i];
        }
    }
    return null;
}




function ShowQrH5MubanEditForm(id) {
    QrH5MubanModel.selRow = fun_FindRowById(id);
    if (QrH5MubanModel.selRow == null) {
        QrH5MubanModel.selRow={};
        QrH5MubanModel.postAction = 'add';
    }
    else {
        QrH5MubanModel.postAction = 'update';
    }

    var url =Onluy.basePath()+QrH5MubanModel.url+"/edit?&mubanId=" + QrH5MubanModel.selRow['mubanId'] ;
    var title=(QrH5MubanModel.postAction == 'add') ? '新增'  : '修改' + QrH5MubanModel.selRow[QrH5MubanModel.titleField];
    window.top.ShowPopWindowUrl('1',title, url,'720','0.9');


}
function SaveQrH5Muban() {
    QrH5MubanModel.submit();

}
function DelQrH5Muban( id,title) {
    QrH5MubanModel.del(id,title);
}

function QrH5MubanSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#QrH5Muban_Grid').datagrid('reload');
    }

}

function ReloadQrH5MubanList() {
    $('#QrH5Muban_Grid').datagrid('reload');
}



$(function () {

    $('#QrH5Muban_Grid').datagrid({
        pageSize: 5,
        fit: true,
        singleSelect: true,
        checkbox: false,
        rownumbers: false,
        fitColumns: true,
        pagination: true,
        method: 'post',
        idField: QrH5MubanModel.idField,
        treeField: QrH5MubanModel.titleField,
        url: Onluy.basePath()+QrH5MubanModel.url+'/list',
        loader:QrH5MubanModel.Loader,
        toolbar: '#QrH5Muban_Toolbar',
        columns: [
            [

                { field: 'thumbnail', title: '缩略图', width:10, align: 'left',sortable:true ,
                    formatter: function (value, rec) {
                        return '<img class="thumbnail" src="'+value+'"  />';
                    }},
                { field: 'mubanId', title: '描述', width:80, align: 'left',sortable:false ,
                    formatter: function (value, rec) {
                        return value+'：'+rec['mubanName']+'<br/>'
                            +'路径：'+rec['path']+'<br/>'
                            +'类型：'+rec['typeId']+'<br/>'
                            +'备注：'+rec['remark']+'<br/>'
                            +'创建日期：'+rec['createDate']+'<br/>' ;
                    }},
                {
                    field: 'opt', title: '操作', width: 10, align: 'center',
                    formatter: function (value, rec) {
                        return '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/pencil.gif" onclick="ShowQrH5MubanEditForm(\'' + rec[QrH5MubanModel.idField] + '\');"   />'
                            + '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/delete.gif" onclick="DelQrH5Muban(\'' + rec[QrH5MubanModel.idField] + '\',\'' + rec[QrH5MubanModel.titleField] + '\');"  />';
                    }
                }
            ]
        ],


        onLoadError: function (res) {
            QrH5MubanModel.ShowException(res);
        },
        onLoadSuccess: function (data) {
            if(data.success){ }
            else if(data.msg){
                $.messager.alert('加载错误', data.msg );
            }
        },
        onDblClickRow: function (rowIndex, rowData) {
            ShowQrH5MubanEditForm(rowData[QrH5MubanModel.idField]);
        },
        onBeforeLoad: function (param) {
            $('#QrH5Muban_Grid').datagrid('clearSelections');
            param['catchKey'] = Math.random();
            param['name'] = $('#QrH5Muban_ss').searchbox('getName');
            param['value'] = $('#QrH5Muban_ss').searchbox('getValue');
        }
    });
    //设置分页控件
    var p = $('#QrH5Muban_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 20, //每页显示的记录条数，默认为10
        pageList: [20, 30, 50, 100], //可以设置每页记录条数的列表
        beforePageText: '第', //页数文本框前显示的汉字
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});



